/*
 * @Author: szx
 * @Date: 2022-03-10 15:20:24
 * @LastEditTime: 2022-03-10 15:27:36
 * @Description:
 * @FilePath: \leetcode\1-99\17\17_2.js
 */
/**
 * @param {string} digits
 * @return {string[]}
 */
var letterCombinations = function (digits) {
    if (digits == '') return [];
    const map = new Map([
        ['2', 'abc'],
        ['3', 'def'],
        ['4', 'ghi'],
        ['5', 'jkl'],
        ['6', 'mno'],
        ['7', 'pqrs'],
        ['8', 'tuv'],
        ['9', 'wxyz']
    ]);
    const res = [];
    const backtrack = (str, index) => {
        if (index == digits.length) {
            res.push(str);
            return;
        }
        for (let j of map.get(digits[index])) {
            backtrack(str + j, index + 1);
        }
    };
    backtrack('', 0);
    return res;
};
console.log(letterCombinations('23'));
